using System;
using System.Collections.Generic;
using WindowsPhoneEssentials.Abstractions;
using WindowsPhoneMVC.Interfaces;
using WindowsPhoneMVC.Navigation;

namespace WindowsPhoneMVC.Tests.Navigation.Fakes
{
    public class FakeJournal : IJournal
    {
        private readonly Stack<NavigationRequest> requests = new Stack<NavigationRequest>();
        private IDictionary<string, object> store;

        public string NavigationFrameName { get; set; }

        public Stack<NavigationRequest> Requests
        {
            get { return requests; }
        }

        public int FlushReceivedCount { get; private set; }

        public void Initialise(IPhoneApplicationService phoneApplicationService)
        {
            store = phoneApplicationService.State;
        }

        public NavigationRequest PopEntry()
        {
            if (requests.Count > 0)
                return requests.Pop();
            return null;
        }

        public void PushEntry(NavigationRequest request)
        {
            requests.Push(request);
        }

        public void Flush()
        {
            FlushReceivedCount++;
            store[Journal.JournalKeyPattern] = requests;
        }

        public bool IsEmpty()
        {
            return requests.Count == 0;
        }
    }
}